package com.cqan.entity.account;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.cqan.entity.pk.IdEntity;

/**
 * @author slaton
 *
 * 下午03:06:30
 */
@Entity
//表名与类名不相同时重新定义表名.
@Table(name = "SYS_RESOURCE")
//默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Resource extends IdEntity {

	/**
	 * 显示名称
	 */
	private String name;
	
	/**
	 * 系统操作标识
	 */
	private String ename;
	
	/**
	 * 状态 0:正常，1:停用
	 */
	private Byte status;
	
	/**
	 * 资源地址
	 */
	private String url;
	

	
	private Resource parent;
	
	private List<Resource> children;
	
	/**
	 * 类型 0：普通资源，1:菜单
	 */
	private Integer type;
	
	private String icon;
	
	
	public String getIcon() {
		return icon;
	}


	public void setIcon(String icon) {
		this.icon = icon;
	}

	@ManyToOne
	@JoinColumn(name="pid")
	public Resource getParent() {
		return parent;
	}


	public void setParent(Resource parent) {
		this.parent = parent;
	}
	

	@OneToMany(mappedBy = "parent", cascade = { CascadeType.REFRESH}, fetch = FetchType.LAZY, targetEntity = Resource.class)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<Resource> getChildren() {
		return children;
	}

	public void setChildren(List<Resource> children) {
		this.children = children;
	}


	public Integer getType() {
		return type;
	}

	
	public void setType(Integer type) {
		this.type = type;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}


	public String getName() {
		return name;
	}

	
	public void setName(String name) {
		this.name = name;
	}

	
	public String getEname() {
		return ename;
	}

	
	public void setEname(String ename) {
		this.ename = ename;
	}

	
	public Byte getStatus() {
		return status;
	}

	
	public void setStatus(Byte status) {
		this.status = status;
	}
	
}
